package test;

import B1.Event;

import B1.State;
import B1.Thermostatic_water_tank;
import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.Test;

public class B1test {
    @Test //当有水且水温低，并且没有进入休眠状态（若处于7:00-23:00点内）
    void when_has_water_and_temperature_lower_the_lowest_and_is_time_to_relayon_should_convert_to_on_status() {
        Thermostatic_water_tank thermostatic_water_tank = new Thermostatic_water_tank();
        thermostatic_water_tank.setEmptyWater(false); //水非空
        thermostatic_water_tank.setTep_is_low(true); //水温低于20度
        thermostatic_water_tank.fire(Event.Relay_power_turnoff); //先进入继电器为关闭的待机状态
        thermostatic_water_tank.fire(Event.Relay_power_turnon); //开始烧水
        State state = thermostatic_water_tank.getCurrentState();
        Assertions.assertThat(state).isEqualTo(State.Relay_power_on);
    }
    @Test //当没水且水温低，并且没有进入休眠状态（若处于7:00-23:00点内）
    void when_no_water_and_temperature_lower_the_lowestand_is_time_to_relayon_should_convert_to_on_status() {
        Thermostatic_water_tank thermostatic_water_tank = new Thermostatic_water_tank();
        thermostatic_water_tank.setEmptyWater(true); //水空
        thermostatic_water_tank.setTep_is_low(true); //水温低于20度
        thermostatic_water_tank.fire(Event.Relay_power_turnoff); //先进入继电器为关闭的待机状态
        thermostatic_water_tank.fire(Event.Relay_power_turnon);
        State state = thermostatic_water_tank.getCurrentState();
        Assertions.assertThat(state).isEqualTo(State.Relay_power_off);
    }
    @Test //当没水且水温低，并且进入休眠状态（若不处于7:00-23:00点内）由于时间是系统时间，测试时请在规定时间内测试
    void when_has_water_and_temperature_lower_the_lowest_and_is_time_to_relayon_and_then_is_time_to_sleep_should_convert_to_on_status() {
        Thermostatic_water_tank thermostatic_water_tank = new Thermostatic_water_tank();
        thermostatic_water_tank.setEmptyWater(false); //水非空
        thermostatic_water_tank.setTep_is_low(true); //水温低于20度
        thermostatic_water_tank.fire(Event.Relay_power_turnoff); //先进入继电器为关闭的待机状态
        thermostatic_water_tank.fire(Event.Relay_power_turnon); //开始烧水
        thermostatic_water_tank.fire(Event.toSleep);
        State state = thermostatic_water_tank.getCurrentState();
        Assertions.assertThat(state).isEqualTo(State.Sleep);
    }
    @Test //水箱烧坏
    void when_no_config_specified_event_should_throw_exception() {
        Thermostatic_water_tank thermostatic_water_tank = new Thermostatic_water_tank();
        thermostatic_water_tank.setEmptyWater(true);
        Assertions.assertThatThrownBy(() -> thermostatic_water_tank.fire(Event.burningOut), "当前状态不接受指定事件", IllegalStateException.class);
    }
}

